#include "stm32f10x.h"
#include "delay.h"
#include "usart.h"
#include <stdio.h>
#include "i2c.h"



//字符发送函数重写
int fputc(int ch,FILE*f){
	//等待TDR为空
	while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
	USART_SendData(USART1,(uint8_t)ch); 
	return ch;
}

int main(){

	i2c_init();
	
	uint8_t commands[]={
		0x00,
		0x8d,
		0x14,0xaf,0xa5
	};


	i2c_send_bytes(I2C1,0x78,commands,5);

	uint8_t rcvd;

	i2c_recv_bytes(I2C1,0x78,&rcvd,1);
	if(rcvd&(0x01<<6)==0){
		GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);
	}

	if(rcvd&(0x01<<6)==0){
		GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);
	}




	while(1){


	}


}



#if 0
int main(void)
{
	GPIO_InitTypeDef structure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

	structure.GPIO_Mode = GPIO_Mode_Out_OD; // 推挽输出
	structure.GPIO_Pin = GPIO_Pin_13;
	structure.GPIO_Speed = GPIO_Speed_50MHz;

	Delay_Init();
	// 使能GPIOC时钟

	GPIO_Init(GPIOC, &structure);
	Led_on();
	while (1)
	{
		GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_SET);

		Delay(100);
		GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_RESET);
		Delay(100);
	}
}

#endif



